package com.zgkxzx.vediotest.page

import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.zgkxzx.vediotest.nativeapi.NativeApi
import com.zgkxzx.vediotest.utils.Constants
import com.zgkxzx.vediotest.utils.FileUtil

class GifConvertH264Activity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            rootView()
        }
    }

    @Composable
    private fun rootView() {
        Column {
            button("拷贝gif到处理目录") {
                copyGif()
            }

            button("转换") {
                convertH264()
            }
        }
    }

    private fun copyGif() {
        val targetPath = Constants.getTestPath(this)
        FileUtil.copy(this, Constants.GIF_TEST_NAME, targetPath, Constants.GIF_TEST_NAME)
        Toast.makeText(this,"拷贝成功 $targetPath", Toast.LENGTH_LONG).show()
    }

    private fun convertH264() {
        NativeApi.convertH264( Constants.getHandleGifPath(this@GifConvertH264Activity, "test"),
            Constants.getHandleVideoPath(this@GifConvertH264Activity, "convert"),)
    }

    @Composable
    private fun button(text: String, click: () -> Unit) = Button(
        onClick = click, modifier = Modifier
            .padding(10.dp)
            .fillMaxWidth()
    ) {
        Text(text = text)
    }
}